package yxboot.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.FlashMap;

import javax.annotation.Resource;


/**
 * Created by yuxi on 16/11/25.
 */
@RestController
@RequestMapping("/hello")
public class HelloController {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Resource(name="redisTemplate")
    ValueOperations<Object,Object> valOps;

    @ApiOperation("test")
    @ApiResponses({
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对"),
            @ApiResponse(code = 500, message = "内部服务错误")
    })
    @RequestMapping(value = "/redis", method = RequestMethod.GET)
    public Object getTest() {
        valOps.set("key","yuxi");
        Object val =  valOps.get("key");
        return val;
    }

    @ApiOperation("test")
    @ApiResponses({
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对"),
            @ApiResponse(code = 500, message = "内部服务错误")
    })
    @RequestMapping(value = "/del", method = RequestMethod.GET)
    public Object del() {
        try {

            redisTemplate.delete("key");
            return true;
        }catch (Exception e){

            return false;
        }
    }
}
